package com.javayh.util.timer;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.logging.Logger;

/**
 * @author Dylan Yang
 * @Title: TimerUtil
 * @ProjectName lucky
 * @Description: TODO
 * @date 2018/10/7 12:32
 */
@Component
public class TimerUtil {

    private Logger logger = Logger.getLogger(getClass().getName());

    /**
      * cron 以10秒为一间隔进行
      * @author Dylan Yang
      */
//    @Scheduled(cron = "0,10,20,30,40,50 * * * * ? *")
    public void timedTaskOne(){
        try {
            logger.info("timedTaskOne -> "+Thread.currentThread().getName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
      * 异步
      * @author Dylan Yang
      */
//    @Scheduled(cron = "0,10,20,30,40,50 * * * * ? *")
    @Async
    public void timedTaskTwo() {
        try {
            logger.info("timedTaskTwo - >"+Thread.currentThread().getName());

            Thread.sleep(1000*20);
            logger.info("timedTaskTwo - >"+Thread.currentThread().getName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}

